import Vue from 'vue'
import App from './App.vue'
// 导入路由模块
import router from './router'
// 导入element组件库
import './plugins/element.js'
// 树形表格插件
import TreeTable from 'vue-table-with-tree-grid'
// 导入全局css文件
import './assets/fonts/iconfont.css'
import './assets/css/global.css'

import axios from 'axios'
// 引入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'

// require styles
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

Vue.use(VueQuillEditor)

// 引入elem组件库
// import { Button, Form, Input, FormItem } from 'element-ui'

// Vue.use(Form)
// Vue.use(Button)
// Vue.use(Input)
// Vue.use(FormItem)

Vue.config.productionTip = false
axios.defaults.baseURL = 'http://42.192.71.221:8889/api/private/v1/'
// 添加请求拦截器-------------------------
axios.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么
  const token = window.sessionStorage.getItem('token')
  // console.log(token)
  if (token) {
    config.headers.Authorization = token
  }
  return config
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error)
})

Vue.prototype.$http = axios
// 全局注册vue-table插件
Vue.component('TreeTable', TreeTable)

// 定义过滤器
Vue.filter('dataFormmat', function (time) {
  const dt = new Date(time * 1000)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1).toString().padStart(2, '0')
  const d = (dt.getDate()).toString().padStart(2, '0')

  return `${y}年${m}月${d}日`
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
